package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.server.service.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @auther : 白月尘
 * @date : 18:13  2021/10/23
 */
@RestController
@RequestMapping("/messages")
public class MessagesController {
    @Autowired
    private MessagesService messagesService;

    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map map){
        String userId = map.get("userId").toString();
        Long id = Long.valueOf(userId);
        messagesService.contacts(id);
        return ResponseEntity.ok(null);
    }
    @GetMapping("/contacts")
    public ResponseEntity contacts(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pageResult=messagesService.findFriends(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }
    @GetMapping("/userinfo")
    public ResponseEntity userInfo(String huanxinId){
        UserInfoVo userInfoVo=messagesService.userInfo(huanxinId);
        return ResponseEntity.ok(userInfoVo);
    }
}
